package com.shop.service.impl;

import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.shop.entity.ShopProduct;
import com.shop.mapper.ShopProductMapper;
import com.shop.service.ShopProductService;
import org.springframework.stereotype.Service;

/**
 * 商品 服务层实现。
 *
 * @author 彭新才
 * @since 2024-10-12
 */
@Service
public class ShopProductServiceImpl extends ServiceImpl<ShopProductMapper, ShopProduct> implements ShopProductService {

    @Override
    public boolean add(ShopProduct shopProduct) {
        ShopProduct product = getOne(new QueryWrapper().eq(ShopProduct::getName, shopProduct.getName()));
        if (product != null) {
            throw new RuntimeException("商品名称重复");
        }
        return save(shopProduct);
    }
}
